package view;

import Util.ActionContext;
import com.google.gson.Gson;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class JsonView implements ViewResult {
    private String json;
    public JsonView(Object data){
            json=new Gson().toJson(data);
    }
    @Override
    public void execute() {
        try {
            HttpServletResponse response =  ActionContext.getContext().getResponse();
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().print(json);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
